package leecode

import "strconv"

func compressString(S string) string {
	last := 0
	arr := []byte(S)
	var result string
	for last < len(arr) {
		count := 0
		temp := arr[last]
		for last < len(arr) && temp == arr[last] {
			last++
			count++
		}
		result += string(arr[last-1]) + strconv.Itoa(count)
	}
	if len(result) >= len(S) {
		return S
	}
	return result
}
